package march.test_3_31;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class TestMain2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        List<List<Integer>> lists = new ArrayList<>();
        for(int i = 0; i < m; i++) {
            lists.add(new ArrayList<>());
        }
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            String color = scanner.nextLine();
            if(color.charAt(0) == 'M') {
                lists.get(a).add(b);
                lists.get(b).add(a);
            }
        }
        int result = retu(lists);
        System.out.println(result);
    }
    public static int retu(List<List<Integer>> list) {
        int count = 0;
        int n = list.size();
        for(int i = 0; i < n; i++) {
            boolean tmp = true;
            for(int j : list.get(i)) {
                if(list.get(j).contains(i)){
                    tmp = false;
                    break;
                }
            }
            if (tmp) {
                count++;
            }
        }
        return count;
    }
}
